package com.whu.aircraft;


import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.CollectionType;
import com.whu.util.JacksonUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static com.whu.util.JacksonUtil.objectMapper;

//航线任务
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName("flight_task")
public class FlightTask {
    @TableId(type = IdType.AUTO)
    private Long flightTaskId;
    private String flightTaskName;//飞行任务名
    private float defaultVelocity;//默认速度，如果航点不指定速度使用此默认速度
    private float defaultHeight;//默认高度，同上
    private String routePoints;//航点组对象Json字符串
    private Date createTime;//任务创建时间
    private Date updateTime;//任务修改时间
    @TableField(exist = false)
    private ArrayList<RoutePoint> route;//航点组

    public void route2Json() throws JsonProcessingException {
        this.routePoints = objectMapper.writeValueAsString(this.route);
    }
    public void json2Route() throws JsonProcessingException {
        CollectionType collectionType = objectMapper.getTypeFactory()
                .constructCollectionType(ArrayList.class,RoutePoint.class);
        this.route = objectMapper.readValue(this.routePoints,collectionType);
    }
}
